<?php

class Js extends ExportConverter {


	public function Export(){
		if ( is_null($this->value) )
			return 'null';
		if ( is_string($this->value) )
				return "'".str_replace(array("\\","'"),array("\\\\","\\'"),$this->value)."'";
		if ( is_bool($this->value) )
			return $this->value ? 'true' : 'false';
		if ( is_int($this->value) )
			return sprintf('%d',$this->value);
		if ( is_float($this->value) )
			return sprintf('%F',$this->value);
		if ( $this->value instanceof GenericID )
			return "'" . $this->value->Encode() . "'";
		if ( $this->value instanceof ID )
			return "'" . $this->value->AsHex() . "'";
		if ( $this->value instanceof DBItem )
			return "'" . $this->value->id->AsHex() . "'";
		if ( $this->value instanceof TimeSpan )
			return $this->value->GetTotalSeconds();
		if ( $this->value instanceof ImmutableDateTime )
			return 'new Date('.$this->value->GetYear().','.($this->value->GetMonth()-1).','.$this->value->GetDay().','.$this->value->GetHours().','.$this->value->GetMinutes().','.$this->value->GetSeconds().')';
		if ( $this->value instanceof DateTime )
			return strval( new Js(new ImmutableDateTime($this->value)) );
		if ( $this->value instanceof Action)
			return "'".str_replace("'","\'",$this->value->GetHref())."'";
		return "'".str_replace("'","\'",strval($this->value))."'";
	}


	const BEGIN = "<script type=\"text/javascript\">\n//<![CDATA[\n";
	const END = "\n//]]>\n</script>";

}



?>
